import modules from './modules' //路由表
import Vue from 'vue';
import Router from 'uni-simple-router';
import layout from "@/components/layout/layout.vue";

Vue.use(Router)
//初始化
const router = new Router({
    h5: {
    	vueRouterDev: true, //完全使用vue-router开发 默认 false  
    	loading: true,
    	resetStyle: () => { //对样式进行追加
    		return {
    			style: `
    					#router-loadding .loadding {
    						background-color: #f00 !important;
    						box-shadow: 0 0 15px #f00 !important;
    					}
    					`
    		}
    	}
    },
    routes: [
		...modules, // 其他嵌套页面路由表
		{
    		path: '/',
    		component: layout,
			redirect:"/home",
    		children: [
				{
					path:"home",
					name:"home",
					meta:{title:"首页",curMenuItem:"1"},
					component:()=>import("@/pages/home/home.vue")
				}
			]
    	},
		{
			path:"/project",
			component:layout,
			redirect:"/project/doc_reference",
			children: [
				{
					path:"doc_reference",
					name:"doc_reference",
					meta: {
						title: "模板参考"
					},
					component: () => import('@/pages/project-doc-reference/project-doc-reference.vue'),
				}
			]
		},
		{
			path:"/about",
			component:layout,
			redirect:"/about/index",
			children: [
				{
					path:"index",
					name:"index",
					meta: {
						title: "关于我们"
					},
					component: () => import('@/pages/about/about.vue')
				}
			]
		},
		{
			path:"*",
			meta: {
				title: "亲，我走丢了"
			},
			component: () => import('@/pages/not-found/not-found.vue'),
		}
    ]
});

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	// #ifdef H5
		window.document.title = to.meta.title;
	// #endif
	next()
})
// 全局路由后置守卫
// router.afterEach((to, from) => {
// 	console.log(to, from)
// })
export default router;